package com.bjpowernode.crm.web.controller;

import com.bjpowernode.crm.pojo.Page;
import com.bjpowernode.crm.service.TranService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("tran")
public class TranController {

    @Autowired
    private TranService tranService;

    @GetMapping("page.json")
    public Page page(Page page, @RequestParam Map map) {
        tranService.getPage(page, map);
        return page;
    }

    @GetMapping("poss.json")
    public Map poss(/*String stage, */HttpServletRequest request) {
        //ResourceBundle rb = ResourceBundle.getBundle("stage2poss");
        //return rb.getString(stage);

        //ServletContext servletContext = request.getServletContext();
        //Map<String,String> possMap = (Map)servletContext.getAttribute("possMap");
        //return possMap.get(stage);

        return (Map)request.getServletContext().getAttribute("possMap");
    }

    @GetMapping("charts.json")
    public List charts() {
        return tranService.getCharts();
    }

}
